package com.example.flshtarvel.controller;

import com.example.flshtarvel.service.ArticleCollectMapService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

@RestController
public class ArticleCollectMapController {
    @Autowired
    ArticleCollectMapService articleCollectMapService;

    //信息收藏
    //@GetMapping("/articleCollect{articleId}")
    //public Map<String,Object> articleCollect(@PathVariable("articleId") String articleId, HttpSession session){
    @GetMapping("/articleCollect")
    public Map<String,Object> articleCollect(
                                             @RequestParam("articleId") String articleId,
                                             @RequestParam("userId") String userId){
        Map<String,Object> map = new HashMap<String,Object>();
        int result = articleCollectMapService.articleCollect(articleId,userId);
        if(result==1){
            map.put("msg",1);
        }else{
            map.put("msg",0);
        }
        return map;
    }
    //取消信息收藏
   // @GetMapping("/deleteArticleCollect{articleId}")
   // public Map<String,Object> deleteArticleCollect(@PathVariable("articleId") String articleId,HttpSession session){
    @GetMapping("/deleteArticleCollect")
    public Map<String,Object> deleteArticleCollect(
                                                   @RequestParam("articleId")String articleId,
                                                   @RequestParam("userId")String userId){
        Map<String,Object> map = new HashMap<String,Object>();
        int result = articleCollectMapService.deleteArticleCollect(articleId,userId);
        if(result>=1){
            map.put("msg",1);
        }else{
            map.put("msg",0);
        }
        return map;
    }
}
